package com.py.framework.activiti.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.py.framework.activiti.dao.WorkflowDao;
import com.py.framework.activiti.entity.WorkFlowBus;
import com.py.framework.activiti.service.WorkflowService;

/**
 * 工作流Service实现
 * @author Leegern
 * @date   2018年5月24日
 */
@Service
public class WorkflowServiceImpl implements WorkflowService {
	
	@Autowired
	private WorkflowDao workflowDao;
	
	/*
	 * (non-Javadoc)
	 * @see com.py.framework.service.WorkflowService#getActsByName(java.lang.String)
	 */
	@Override
	public int getActsByName(String actName) {
		if (StringUtils.isNotBlank(actName)) {
			return workflowDao.getActsByName(actName);
		}
		return 0;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.py.framework.service.WorkflowService#findActByProcId(java.lang.String)
	 */
	@Override
	public WorkFlowBus findActByProcId(String procId) {
		if (StringUtils.isNotBlank(procId)) {
			List<WorkFlowBus> datas = workflowDao.findActByProcId(procId);
			if (! CollectionUtils.isEmpty(datas)) {
				return datas.get(0);
			}
		}
		return null;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.py.framework.service.WorkflowService#updateWorkFlowBus(com.py.framework.entity.WorkFlowBus)
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public int updateWorkFlowBus(WorkFlowBus workflow) {
		if (null != workflow) {
			return workflowDao.updateWorkFlowBus(workflow);
		}
		return 0;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.py.framework.service.WorkflowService#addWorkFlowBus(com.py.framework.entity.WorkFlowBus)
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public int addWorkFlowBus(WorkFlowBus entity) {
		if (null == entity) {
			return workflowDao.addWorkFlowBus(entity);
		}
		return 0;
	}
}